package com.hns.can.safety.service;

import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.aop.orgTree.DriverInterfaceAnnotation;
import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.mainte.entity.CommLogFileRcdEntity;
import com.hns.can.mainte.vo.LoadFileParamVo;
import com.hns.can.master.entity.CommAccDobPoitInfoEntity;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;
import com.hns.tool.pub.SearchConditionVo;

/**
 * 事故疑点service
 * @author:zhangy
 * @email:
 * @version Revision 2.0.0
 */
@Service
public class AccidentPointService extends CommonService {
	
	@Autowired
    private FillCodeDscValue codeDscValue;
	
	private <T> List<T> fillColVal(List<T> list) throws Exception{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("drvName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo1 = new FillParamsVo("drvId", map);
		
		map = new HashMap<String, String>();
		map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo2 = new FillParamsVo("lineId", map);
		
		map = new HashMap<String, String>();
		map.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo3 = new FillParamsVo("organId", map);
		
		codeDscValue.fillInfoValue(list, new String[]{GlobalConst.CACHE_KEY_BASE_DRV_INFO, 
				GlobalConst.CACHE_KEY_BASE_LINE_INFO, GlobalConst.CACHE_KEY_BASE_ORGAN}, vo1, vo2, vo3);
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<CommLogFileRcdEntity> getCommLogFileRcdByTimeList(LoadFileParamVo entity) {
        List<CommLogFileRcdEntity> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("loadFileMonitor.getLogFileRcdByTimeList", entity), CommLogFileRcdEntity.class);
        return list;
    }
	
	
	/**
     * getAccidentPointPage(事故疑点分页数据查询)    
     * @param   conditionVo 查询条件
     * @return
     */
    @LeftOrgAnnotation()
    @Transactional
    @DriverInterfaceAnnotation()
	public Pagination getAccidentPointPage(SearchConditionVo conditionVo) throws Exception{
   		// 查询对应时间范围的事故疑点数据。
    	Pagination page = this.myBatisPage("accidentPointMonitor.getAccidentPointCount", "accidentPointMonitor.getAccidentPointInfo", conditionVo, CommAccDobPoitInfoEntity.class);
	    fillColVal(page.getData());	   
	    return page;
	}
    
    @SuppressWarnings("unchecked")
	@Transactional
	public List<CommAccDobPoitInfoEntity> getAccidentPointChart(HttpServletRequest request) throws Exception {
		HashMap<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("LIC_PLT_NO", request.getParameter("licPltNo"));
		paramMap.put("ACDN_DO_POI_TIME", request.getParameter("rcrdTime"));
		List<CommAccDobPoitInfoEntity> commAccDobPoitInfoList = PubUtil.convertListMapToObject(sqlMapDao.selectList("accidentPointMonitor.getAccidentPointChart", paramMap), CommAccDobPoitInfoEntity.class);
		fillColVal(commAccDobPoitInfoList);
		return commAccDobPoitInfoList;
	}
}
